home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0024_Factoring Program.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  806b  |  32 lines

  1. {LOU DUCHEZ
  2.  
  3. > Could anybody explain how to Write such a routine in Pascal?
  4.  
  5. Here's a dorky little "Factoring" Program I wrote to display the factors
  6. of a number:
  7. }
  8.  
  9. Program factors;
  10. Var
  11.   lin,
  12.   lcnt : LongInt;
  13. begin
  14.   Write('Enter number to factor: ');
  15.   readln(lin);
  16.   lcnt := 2;
  17.   While lcnt * lcnt <= lin do
  18.   begin
  19.     if lin mod lcnt = 0 then
  20.       Writeln('Factors:', lcnt : 9, (lin div lcnt) : 9);
  21.     lcnt := lcnt + 1;
  22.   end;
  23. end.
  24.  
  25. {
  26. Notice that I only check For factors up to the square root of the number
  27. Typed in.  Also, notice the "mod" operator: gives the remainder of Integer
  28. division ("div" gives the Integer result of division).
  29.  
  30. Not Really knowing exactly what you want to accomplish, I don't Really know
  31. if the above is of much help.  But what the hey.
  32. }